import axios from 'axios';
import { React, useEffect, useState } from 'react';
import '../../../index.css';
import { Pagination } from 'antd';
import InterIP from '../../../IP/IP'
import { useNavigate } from 'react-router-dom';


export default function Notasy() {

    const [unsentarr, setunsentarr] = useState([]);
    const [twoData, settwoData] = useState([])
    const navigate = useNavigate()

    useEffect(() => {
        const toolsArr = [];
        var userID = document.cookie.slice(5);
        let IP = InterIP().props.children;
        axios.post("http://" + IP + ":3000/user/selIndent", {
            user_id: userID,
        })
            .then((res) => {
                res.data.forEach((v, k) => {
                    if (v.order_status === '待评价') {
                        toolsArr.push(v);
                    }
                });
                var bigArr = []
                toolsArr.forEach((val, key) => {
                    bigArr.push({ "arr": [], "id": key });
                    val.product.split('+').forEach((v, k) => {
                        bigArr[key].arr.push(JSON.parse(v));
                    })
                });

                settwoData((twoData) => twoData = bigArr);
                setunsentarr((unsentarr) => unsentarr = toolsArr)
            })

    }, []);


    function allorder_gosay(data) {
        return () => {
            navigate('/home/person/orderto', {
                state: {
                    data: data,
                }
            })
        }
    }
    return (
        <div>
            {unsentarr.map((data, k) => {
                return (
                    <div className="allorder_card" key={data.order_id}>
                        <div className="allorder_card_top">
                            <ul>
                                <li>订单号:<span>{data.order_id}</span></li>
                                <li>下单日期:<span>{data.order_time}</span></li>
                                <li>{data.stroe_id}</li>
                                <li>订单状态:<span>{data.order_status}</span></li>
                            </ul>
                        </div>
                        <div className="allorder_bottom">
                            <div className="allorder_card_main">


                                {twoData[k].arr.map((data, key) => {
                                    return (
                                        <div className="allorder_card_main_left" key={key}>
                                            <div className="allorder_card_left">
                                                <div className="allorder_card_img">
                                                    <img src={data.product_img} alt=""></img>
                                                </div>
                                                <span>{data.product_name}</span>
                                            </div>

                                            <div className="allorder_card_left">
                                                <span>{data.product_number}{data.product_specification}</span>
                                            </div>

                                            <div className="allorder_card_left">
                                                <span>￥</span>
                                                <span>{data.product_price}</span>
                                                <span>&nbsp;&nbsp;*&nbsp;&nbsp;</span>
                                                <span>{data.buy_number}</span>
                                            </div>
                                        </div>
                                    )
                                })}


                            </div>

                            <div className="lfy_small">
                                <div className="allorder_card_right1">
                                    <div>店铺合计：￥<span>{data.total_price}</span></div>
                                    <div>(含运费:￥<span>{data.freight}</span>)</div>
                                </div>
                                <div className="allorder_card_right2">
                                    <button className="allorder_chakan">查看详情</button>
                                    <button className='allorder_shanchu'>删除订单</button>
                                    <button className='allorder_pingjia' onClick={allorder_gosay(data)}>去评价</button>
                                </div>
                            </div>


                        </div>
                    </div>
                )
            })}
            <Pagination className="allorder_page" total={30} pageSize={6}></Pagination>
        </div>
    )
}
